package com.woniu.adopt.web;

import com.mysql.cj.log.LogFactory;
import com.woniu.adopt.ExceptionHandler.BizException;
import com.woniu.adopt.service.OssUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传
 * 返回地址 或 字符串
 */
@RestController
@RequestMapping("oss")
@Api(description = "文件上传接口")
public class OSSUploadController {
    @Autowired
    OssUploadService uploadService;

    @ApiOperation(value = "图片上传功能")
    @PostMapping("/upload")
    public String upload(@RequestParam("file") MultipartFile multipartFile) {
        if(multipartFile==null){
            throw  new BizException("-1", "没有获得上传文件");
        }
        String result = uploadService.uploadImg(multipartFile);
        return result;
    }
}
